/*
 * xzlib.cpp
 *
 *  Created on: 14 sept. 2011
 *      Author: lindenb
 */
#include <cstring>
#include <cerrno>
#include "xstdlib.h"
#include "xzlib.h"
#include "throw.h"

using namespace std;

GZReader::GZReader(const char* filename):in(NULL)
	{
	in=gzopen(filename,"r");
	if(in==NULL)
		{
		free(buffer);
		buffer=NULL;
		THROW("Cannot open "<< filename << " " << strerror(errno));
		}
	}
GZReader::GZReader()
    {
    in=gzdopen(fileno(stdin),"r");
    if(in==NULL)
	    {
	    free(buffer);
	    buffer=NULL;
	    THROW("Cannot open stdin");
	    }
    }
GZReader::~GZReader()
	{
	close();
	}

void GZReader::close()
	{
	if(in!=NULL) gzclose(in);
	in=NULL;
	}


int GZReader::getc()
	{
	return in==NULL?EOF:gzgetc(in);
	}

int GZReader::eof()
	{
	return in==NULL?1:gzeof(in);
	}
